package Cinema.Tests;

import static org.junit.Assert.assertTrue;

import java.util.List;

import org.custommonkey.xmlunit.DetailedDiff;
import org.custommonkey.xmlunit.Diff;
import org.custommonkey.xmlunit.Difference;
import org.junit.Test;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

import Utils.XmlParseHelper;

import Cinema.CinemaEntities.Movie;
import Exceptions.DataAccessException;
import Exceptions.WrongXMLElement;

public class MovieTest implements IXmlParsableTest{


	@Test
	@Override
	public void test_getXml() throws DataAccessException{

		//create test tdoc
		Movie movie = new Movie("Human Sentampede", "stupid");
		Document testDoc = XmlParseHelper.createNewDocument();
		Element testElement = movie.getXml(testDoc);
		testDoc.appendChild(testElement);

		//create control doc
		Document controlDoc = XmlParseHelper.getDocumentFromFile(".\\tests\\testXml\\MovieTest.xml");

		Diff diff = new Diff(controlDoc, testDoc);
		DetailedDiff detailedDiff = new DetailedDiff(diff);

		//fro debugging
		@SuppressWarnings("unchecked")
		List<Difference> difList = detailedDiff.getAllDifferences();
		for (Difference difference : difList) {
			String discription = difference.getDescription();
			discription.toString();
		}

		boolean isEq = detailedDiff.similar();

		assertTrue(isEq);
	}

	@Test
	@Override
	public void test_initFromXml() throws DataAccessException{
		//create test object
		Movie testMovie = null;
		try {
			testMovie = new Movie(XmlParseHelper.getDocumentFromFile(".\\tests\\testXml\\MovieTest2.xml").getDocumentElement());
		} catch (WrongXMLElement e) {
			e.printStackTrace();
		}

		//create control movie
		Movie controlMovie = new Movie("The Rock", "Action");

		boolean isEq = controlMovie.checkEquals(testMovie);

		assertTrue(isEq);

	}



}
